﻿@using Newtouch.Infrastructure
@{
    ViewBag.Title = "MzPrescriptionQuery";
    Layout = "~/Views/Shared/_Index.cshtml";
    var reportUrl = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportUrl");
    var reportSystemCode = Newtouch.Core.Common.Utils.ConfigurationHelper.GetAppConfigValue("ReportSystemCode");
}
<style>
    #btn_search {
        height: 45px;
        width: 45px;
        background-color: #fff;
        color: #00a9ea;
        font-weight: bolder;
    }

</style>
<div class="rows">
    <form id="form1">
        <div class="panel panel-default">
            <div class="panel-heading">
                查询条件
            </div>
            <div style="padding: 2px;">
                <table class="form">
                    <tr>
                        <td class="formTitle">科室：</td>
                        <td class="formValue">
                            <input type="text" id="ksmc" name="ksmc" placeholder="请选择科室" class="form-control" />
                            <input type="hidden" id="ksdm" name="ksdm" value="" />
                        </td>
                        <th class="formTitle">姓名/门诊号：</th>
                        <td class="formValue">
                            <input id="keyword" type="text" class="form-control" placeholder="姓名/住院号" />
                        </td>
                        <th class="formTitle"><span class="required">*</span>开始时间：</th>
                        <td class="formValue">
                            <input id="kssj" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.ToString("yyyy-MM-01 00:00")" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm:ss'})" />
                        </td>
                        <th class="formTitle"><span class="required">*</span>结束时间：</th>
                        <td class="formValue">
                            <input id="jssj" type="text" class="form-control input-wdatepicker" value="@DateTime.Now.AddHours(2).ToString("yyyy-MM-dd 23:59")" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd 23:59:59'})" />
                        </td>
                        <td class="formTitle" rowspan="2">
                            <input type="button" id="btn_search" class="btn btn-primary btn-md" value="查询" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">处方性质：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select id="cflx" class="form-control">
                                <option value="1">西药处方单</option>
                                <option value="2">中药处方单</option>
                                @*<option value="jycf">检验处方单</option>
                                <option value="jccf">检查处方单</option>
                                <option value="zscf">注射处方单</option>
                                <option value="kfcf">康复处方单</option>
                                <option value="cgcf">常规处方单</option>*@
                            </select>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
    </form>
</div>
<div class="rows">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>
<div class="gridPanel" style="margin-top:10px;">
    <table id="gridListMX"></table>
    <div id="gridPagerMX"></div>
</div>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel
{
    ShowKeyList = new int[] { 6 } ,
    F6Text = "打印"
})

<script type="text/javascript">
    var $gridList = $("#gridList");
    $(function () {
        dispenseMedicinGridList();
        gridInit();
    });

    //回车事件绑定
    $(document).keyup(function (event) {
        if (event.keyCode === 13) {
            $("#btn_search").trigger("click");
        }
    });
    function dispenseMedicinGridList() {
        $gridList.dataGrid({
            multiselect: true,
            url: '/OutPatientPharmacy/GetMzcfGridJson',
            height: $(window).height() - document.getElementById('gridList').offsetTop - 280,
            postData: {
                ks: $("#ksdm").val(), keyword: $("#keyword").val(),
                kssj: $("#kssj").val(), jssj: $("#jssj").val(), cflx: $("#cflx").val()
            },
            colModel: [
                { label: 'cfId', name: 'cfId', width: 150, align: 'left',hidden:true },
                { label: '处方号', name: 'cfh', width: 120, align: 'left' },
                { label: '门诊号', name: 'mzh', width: 120, align: 'left' },
                { label: '姓名', name: 'xm', width: 80, align: 'left' },
                { label: '性别', name: 'xb', width: 50, align: 'left' },
                { label: '科室', name: 'ksmc', width: 100, align: 'left' },
                { label: '医生', name: 'ysmc', width: 80, align: 'center' },
                { label: '总金额', name: 'zje', width: 80, align: 'center' },
                {
                    label: '处方类型', name: 'cflx', width: 90, align: 'center', formatter: function (val) {
                        return val == "1" ? "西药处方" : (val == "2" ? "中药处方" : "");
                    }
                },
                {
                    label: '开单时间', name: 'kssj', width: 120, align: 'left',
                    formatter: "date", formatoptions: { srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s' }
                },
                { label: '特殊处方', name: 'cftag', width: 80, align: 'left',hidden:true },
                { label: '特殊处方', name: 'cftagName', width: 80, align: 'left' },
                {
                    label: '发药标志', name: 'fybz', width: 50, align: 'center', formatter: function (val) {
                        return val== "2" ? "已发药":(val=="3"?"已退药":"未发药");  //$.enum.getDescByValue("EnumFybz", val);
                    }
                }
            ],
            //caption: "处方笺列表",
            pager: "#gridPager",
            rowNum: 10,
            sortname: 'kssj',
            viewrecords: true,
            ondblClickRow: function (rowId) {
                relod(rowId);
                //btn_clickrow(rowId);
            }
        });
        
        
        function btn_clickrow(rowId)
        {
            var cfh = $("#gridList").jqGrid('getRowData', rowId).cfh;
            $.modalOpen({
                id: "GetCfDetail",
                title: "处方明细",
                url: "/OutPatientPharmacy/PrescriptionDetailFrom?cfh=" + cfh,
                width: "950px",
                height: "600px",
                btn: ['', '关闭'],
                callBack: function (iframeId) {
                }
            });
        }

        $("#btn_search").click(function () {
            if ($("#kssj").val() === "") {
                $.modalMsg("开始时间不能为空", "warning", 2000);
                return false;
            }
            if ($("#jssj").val() === "") {
                $.modalMsg("结束时间不能为空", "warning", 2000);
                return false;
            }
            $gridList.jqGrid('setGridParam', {
                postData: {
                    ks: $("#ksdm").val(),
                    kssj: $("#kssj").val(),
                    jssj: $("#jssj").val(),
                    keyword: $("#keyword").val(),
                    cflx: $("#cflx").val()
                }
            }).trigger('reloadGrid');

        });
    }
    function relod(rowId) {
        var cfh = $("#gridList").jqGrid('getRowData', rowId).cfh;
        var $gridList = $("#gridListMX");
        $gridList.jqGrid('setGridParam', {
            postData: {
                cfh: cfh
            }
        }).trigger('reloadGrid');
    }
    function gridInit() {
        var $gridList = $("#gridListMX");
        $gridList.dataGrid({
            postData: { cfh: "" },
            url: '/OutPatientPharmacy/GetMzcfGridDetailJson',
            height: $(window).height() - 450,
            colModel: [
                { label: '门诊号', name: 'mzh', align: 'center', width: 100 },
                { label: '姓名', name: 'xm', align: 'center', width: 60 },
                { label: '开单时间', name: 'kssj', align: 'left', width: 50, hidden: true },
                { label: '药品代码', name: 'ypcode', align: 'center', width: 90 },
                { label: '药品名称', name: 'ypmc', align: 'center', width: 120 },
                { label: '单位', name: 'dw', align: 'center', width: 60 },
                { label: '数量', name: 'sl', align: 'center', width: 50 },
                {
                    label: '单价', name: 'dj', align: 'center', width: 50, formatter: "number"
                    , formatoptions: { decimalPlaces: 2, defaultValue: '0.0000' }
                },
                {
                    label: '费用', name: 'je', align: 'center', width: 60, formatter: "number"
                    , formatoptions: { decimalPlaces: 2, defaultValue: '0.0000' }
                },
                { label: '剂量', name: 'mcjl', align: 'center', width: 60 },
                { label: '规格', name: 'gg', align: 'center', width: 100 },
                { label: '频次', name: 'pcmc', align: 'center', width: 60 },

            ],
            pager: "#gridPagerMX",
            sortname: 'kssj',
            viewrecords: true,
        });
    }
    //初始化科室
    $("#ksmc").newtouchBatchFloatingSelector({
        height: 200,
        width: 360,
        clickautotrigger: true,
        url: "/OutPatientPharmacy/GetTheLowerKsCodeList",
        ajaxmethod: 'POST',
        ajaxreqdata: function () {
            var reqData = {};
            reqData.keyword = $.trim($("#ksmc").val());
            return reqData;
        },
        caption: "科室",
        colModel: [
            { label: '科室编码', name: 'code', width: 100 },
            { label: '科室名称', name: 'name', width: 220 }
        ],
        itemdbclickhandler: function ($thistr) {
            $("#ksmc").val($thistr.attr("data-name"));
            $("#ksdm").val($thistr.attr("data-code"));
            return;
        }
    });

    function newtouch_event_f6() {
        debugger;
        var selRowIds = $("#gridList").jqGrid('getGridParam', 'selarrrow');
        
        if (selRowIds.length == 0) {
            $.modalAlert("请先选中需打印的处方", 'warning');
            return;
        }
        if (selRowIds.length > 1) {
            $.modalAlert("单次只能打印一张处方", 'warning');
            return;
        }
        var seleRow = $("#gridList").jqGridRowValue();
        var cfId = seleRow[0].cfId;
        var mzh = seleRow[0].mzh;
        var cftag = seleRow[0].cftag;
        var tempCode = "14";
        if (cftag == "JI")
            tempCode = "18"
        if (cftag == "JII")
            tempCode = "18"
        if (cftag == "MZ")
            tempCode = "17"
        var rpturl = '@reportUrl' + "?tempCode=" + tempCode + "&systemCode=" + '@reportSystemCode' + "&orgId=" + '@ViewBag.OrganizeId';
        window.open(rpturl + "&mzh=" + mzh + "&cfId=" + cfId, "_blank",
            "height = 500, width = 1195, top = 100, left = 50, toolbar = no, menubar = no, scrollbars = yes, resizable = yes, location = no, status = no");
    }
</script>